package com.maixy.esdemo.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

import java.io.IOException;
import java.util.Arrays;

/**
 * @ClassName ESTestDocInsert
 * @Description TODO
 * @Date 2021/4/16 22:40
 * @Author maixy
 */
public class ESTestDocDeleteBatch {
    public static void main(String[] args) throws IOException {
        RestHighLevelClient esClient =new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200, "http")));

        //批量删除数据
        BulkRequest request = new BulkRequest();
        request.add(new DeleteRequest().index("user").id("1001"));
        request.add(new DeleteRequest().index("user").id("1002"));
        request.add(new DeleteRequest().index("user").id("1003"));

        BulkResponse response = esClient.bulk(request, RequestOptions.DEFAULT);
        System.out.println(response.getTook());
        System.out.println(Arrays.toString(response.getItems()));
        esClient.close();
    }
}
